In [1]:
import matplotlib.pyplot as plt
import pandas as pd
from pandas.tools.plotting import table
import numpy as np
%matplotlib inline
In [44]:
plt.clf() # clear
ax = plt.subplot(111, frame_on=False) # visible frame option false
ax.xaxis.set_visible(False) # hide the x axis
ax.yaxis.set_visible(False) # hide the y axis
df = pd.DataFrame(np.random.randn(10,5)) # make random dataframe
table(ax, df)
plt.savefig('./image/mytable.png')
In [2]:
from IPython.display import HTML
df = pd.DataFrame({'A': np.linspace(1, 3, 3)})
df['image'] = 'retrica.png'
df.iloc[2,1] = 'retrica_1.png'
df['new'] = df['image'].apply(lambda x: '<img src="./image/{}" width="80%" height="80%"/>'.format(x) if x else '')
def hover(hover_color="#ffff99"):
return dict(selector="tr:hover",
props=[("background-color", "%s" % hover_color)])
styles = [
hover(),
dict(selector="th", props=[("font-size", "150%"),
("text-align", "center")]),
dict(selector="caption", props=[("caption-side", "bottom")])
]
html = (df.style.set_table_styles(styles)
.set_caption("Hover to highlight."))
html
Out[2]:
In [43]:
df
Out[43]:
In [ ]:
def sticker_img(name):
if 'Sticker' in name:
return '<img src="./img/{}.png" width="10%" height="10%"/>'.format(name) if name else ''
else:
return change_dict.get(name, name)
In [ ]:
sticker_df['sticker_name'] = sticker_df['sticker'].apply(lambda x: sticker_img(x))